import storageApi from '../../../core/storage/storage';

function supervisorProblemsController($rootScope, $scope, homeStatsService) {
  'ngInject';

  // 问题列表
  this.getProblem = () => {
    const nowDate = new Date().getTime();
    this.hasData = false;
    const param = {
      page: 1,
      size: 5,
      mapParams: {
        orgId: $rootScope.orgId || storageApi.get('orgId'),
      },
    };
    homeStatsService
      .queryProblem(param)
      .then((res) => {
        if (res.success) {
          this.problems = res.rows.splice(0, 4);
          if (this.problems && this.problems.length > 0) {
            this.hasData = true;
            this.problems.forEach((item) => {
              if (item.overdue) {
                item.redColor = { color: '#fd5757' };
              }
            });
          } else {
            this.hasData = false;
          }
        }
      });
  };

  this.getProblem();
}

export default supervisorProblemsController;
